#!/bin/bash 
set -e


TMP=${TMP:-/tmp/work}
LOG=${LOG:-$HOME/logs/stage4}
SRC=${SRC:-/sources}

name=sqlite
version=3.34.1
_version=3340100

rm -rf $TMP
mkdir -p $TMP $LOG

tar xf $SRC/$name-autoconf-$_version.tar.gz -C $TMP

{ time \
   {

    cd $TMP/$name-autoconf-$_version
    
	unzip -q ../$name-doc-$_version.zip

	./configure --prefix=/usr     \
	            --disable-static  \
	            --enable-fts5     \
	            CFLAGS="-g -O2                    \
	            -DSQLITE_ENABLE_FTS3=1            \
	            -DSQLITE_ENABLE_FTS4=1            \
	            -DSQLITE_ENABLE_COLUMN_METADATA=1 \
	            -DSQLITE_ENABLE_UNLOCK_NOTIFY=1   \
	            -DSQLITE_ENABLE_DBSTAT_VTAB=1     \
	            -DSQLITE_SECURE_DELETE=1          \
	            -DSQLITE_ENABLE_FTS3_TOKENIZER=1"
	make

	make install

	install -v -m755 -d /usr/share/doc/$name-$version
	cp -v -R $name-doc-$_version/* /usr/share/doc/$name-$version

    }
} 2>&1 | tee $name.log
    
[ $PIPESTATUS = 0 ] && mv $name.log $LOG || exit $PIPESTATUS

rm -fr $TMP
